<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div></div>
    <script>
        let it = makeIterator();

        // 返回遍历器对象
        function makeIterator(){
            var nextIndex = 0;
            return {
                // 闭包
                next: function (){
                    return nextIndex < 5 ? 
                    { value: nextIndex++, done: false } : { value: undefined, done: true };
                }
            };
        }
        
        
        let obj = {
            [Symbol.iterator]: makeIterator
        };

        // for...of循环
        // for(let value of obj){
        //   console.log('value:',value);
        // }

        // 数组解构
        let arr = [];
        arr[Symbol.iterator] = makeIterator;
        // let [x, y] = arr;
        // console.log(x + '==============' + y);
        // yield
        function* f(){
            // 相当于把arr展开
            yield* arr
        }
        for(let value of f()){
            console.log(value);
        }


        function f1(){
            console.log('arguments:',arguments[Symbol.iterator]);
        }
        f1()
        
        // divs  NodeList对象
        let divs = document.querySelectorAll('div');
        console.log(divs[Symbol.iterator]);
    </script>
</body>
</html>